<body>
<div class="layuimini-main">
    <form class="layui-form" action="" lay-filter="config_form" id="config_form">
         <legend style="font-weight: 800">库存表表字段配置</legend>
        <div class="layui-form-item" >
            <label class="layui-form-label">unique_code</label>
            <div class="layui-input-block" >
                <input type="text" id="unique_code_stock"  lay-verify="title" autocomplete="off" placeholder="寄存码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
                <label class="layui-form-label">item_id</label>
                <div class="layui-input-block">
                    <input type="text" id="item_id_stock" lay-verify="title" autocomplete="off" placeholder="货号" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">item_size</label>
                <div class="layui-input-block">
                    <input type="text" id="item_size_stock" lay-verify="title" autocomplete="off" placeholder="尺码" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">order_id</label>
                <div class="layui-input-block">
                    <input type="text" id="order_id_stock" lay-verify="title" autocomplete="off" placeholder="入库预约单号" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">item_condition</label>
                <div class="layui-input-block">
                    <input type="text" id="item_condition_stock" lay-verify="title" autocomplete="off" placeholder="瑕疵等级" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">order_status</label>
                <div class="layui-input-block">
                    <input type="text" id="order_status_stock" lay-verify="title" autocomplete="off" placeholder="状态" class="layui-input">
                </div>
            </div>
            <legend style="font-weight: 800">需求表字段配置</legend>
                <div class="layui-form-item">
                    <label class="layui-form-label">unique_code</label>
                    <div class="layui-input-block">
                        <input type="text" id="unique_code_require" lay-verify="title" autocomplete="off" placeholder="寄存码" class="layui-input">
                    </div>
                </div>
        <div class="layui-form-item">
                <label class="layui-form-label">item_id</label>
                <div class="layui-input-block">
                    <input type="text" id="item_id_require" lay-verify="title" autocomplete="off" placeholder="货号" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">item_size</label>
                <div class="layui-input-block">
                    <input type="text" id="item_size_require" lay-verify="title" autocomplete="off" placeholder="尺码" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">item_name</label>
                <div class="layui-input-block">
                    <input type="text" id="item_name_require" lay-verify="title" autocomplete="off" placeholder="商品名称" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">order_id</label>
                <div class="layui-input-block">
                    <input type="text" id="order_id_require" lay-verify="title" autocomplete="off" placeholder="入库预约单号" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">item_condition</label>
                <div class="layui-input-block">
                    <input type="text" id="item_condition_require" lay-verify="title" autocomplete="off" placeholder="瑕疵情况" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">order_status</label>
                <div class="layui-input-block">
                    <input type="text" id="order_status_require" lay-verify="title" autocomplete="off" placeholder="状态" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">willing</label>
                <div class="layui-input-block">
                    <input type="text" id="willing_require" lay-verify="title" autocomplete="off" placeholder="处理意向" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">supplier</label>
                <div class="layui-input-block">
                    <input type="text" id="supplier_require" lay-verify="title" autocomplete="off" placeholder="供应商" class="layui-input">
                </div>
            </div>
        <legend style="font-weight: 800">输出表字段配置</legend>
        <div class="layui-form-item">
                <label class="layui-form-label">字段1</label>
                <div class="layui-input-block">
                    <input type="text" id="column_1" lay-verify="title" autocomplete="off" placeholder="商品名称" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">字段2</label>
                <div class="layui-input-block">
                    <input type="text" id="column_2" lay-verify="title" autocomplete="off" placeholder="货号" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">字段3</label>
                <div class="layui-input-block">
                    <input type="text" id="column_3" lay-verify="title" autocomplete="off" placeholder="尺码" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">字段4</label>
                <div class="layui-input-block">
                    <input type="text" id="column_4" lay-verify="title" autocomplete="off" placeholder="寄存码" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">字段5</label>
                <div class="layui-input-block">
                    <input type="text" id="column_5" lay-verify="title" autocomplete="off" placeholder="供应商" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
                <label class="layui-form-label">字段6</label>
                <div class="layui-input-block">
                    <input type="text" id="column_6" lay-verify="title" autocomplete="off" placeholder="瑕疵情况" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submit_btn">立即提交</button>
                </div>
            </div>
        </form>
</div>
</body>
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
<script>
 function getQueryVariable(variable){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    };
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(submit_btn)', function (data) {
            var CurrentStockMap=[
                "unique_code",
                "item_id",
                "item_size",
                "order_id",
                "item_condition",
                "order_status"
                ]
            var RequirementMap=[
                "unique_code",
                "item_id",
                "item_size",
                "item_name",
                "order_id",
                "item_condition",
                "order_status",
                "willing",
                "supplier"
                ]
            var ExportList=["","","","","",""]
            var CurrentStockObj={};
            var RequirementObj={};
            var cl=CurrentStockMap.length;
            var rl=RequirementMap.length;
            var el=ExportList.length;
            for (var i=0;i<cl;i++)
            {
                CurrentStockObj[CurrentStockMap[i]]=data.form[i].value.toString();
            };
            for (var i=cl;i<cl+rl;i++)
            {
                RequirementObj[RequirementMap[i-cl]]=data.form[i].value.toString();
            };
            for (var i=cl+rl;i<cl+rl+el;i++)
            {
                ExportList[i-cl-rl]=data.form[i].value.toString();
            };
            var form_obj={
                "data":{
                      "CurrentStockMap":CurrentStockObj,
                      "RequirementMap":RequirementObj,
                      "ExportColumns":ExportList
                    },
                "date":getQueryVariable("date")
            }
            var data_obj=JSON.stringify(form_obj);
            $.ajax({
                type : 'POST',
                url : "/api/config",
                data : data_obj,
                dataType: "json",
                contentType:'application/json',
                async: false,
                success : function(result){
                    if (result.success == "false") {
                        alert("添加失败!");
                        layer.closeAll('dialog');
                    }
                    else if (result.exception == "true"){
                        alert("服务器异常");
                        layer.closeAll('dialog');
                    }
                    else if (result.success == "true"){
                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    }
			    },error : function(result){
			            console.log(result);
                    }
		    });
        });
    });
</script>